<!DOCTYPE html>
<html>
<head>
    <title>Hello WebSocket</title>
</head>
<body>

<div>Hello WebSocket</div>
<div id="content">

</div>

<script src="/static/js/jquery-3.2.1.min.js"></script>
<script>
    var ws = new WebSocket('ws://localhost:8080/helloWebSocket');
    var f;
    ws.onopen = function () {
        f = setInterval(function () {
            ws.send('Hello Server!')
        }, 5000)
    };

    ws.onclose = function () {
        clearInterval(f);
    };

    ws.onmessage = function (event) {
        console.log(event);
        $("#content").append("<p>" + event.data + "</p>");
    };
</script>
</body>
</html>